<?php
namespace Pinenut;

use Libmail\Mail as Adapter;
class Mail {
	public $from, $to, $subject, $content;
	
	function __construct($params = array()) {
		foreach ($params as $key => $value) {
			if (property_exists($this, $key)) {
				$this->$key = $value;
			}
		}
	}
	
	function send() {
		// пока тупо использую либу влоб
		
		$config = \SmtpConfig::get();
		
		$adapter = new Adapter();
		$adapter->From($this->from?$this->from:$config['from']);
		$adapter->To($this->to);
		$adapter->Subject($this->subject);
		$adapter->Body($this->content);
		$adapter->smtp_on($config['host'], $config['login'], $config['password']);
		if (!$adapter->Send()) {
			throw new \Exception($adapter->status_mail['message']);
		}
	}
}